<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>Beego_Admin</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/static/css/font.css">
    <link rel="stylesheet" href="/static/css/xadmin.css">
    <script src="/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="/static/js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">系统工具</a>
            <a href="">代码生成</a>
            <a>
              <cite>可选数据表</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" action="">
                        <div class="layui-inline layui-show-xs-block">
                            <input type="text" name="table_name"  placeholder="关键词" autocomplete="off" class="layui-input" value="{{.key_word}}">
                        </div>
                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn"  lay-submit="search" lay-filter="search"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" onclick="multi_import()">导入</button>
                </div>
                <div class="layui-card-body ">
                    <table class="layui-table layui-form">
                        <thead>
                        <tr>
                            <th>
                                <input type="checkbox" name=""  lay-skin="primary">
                            </th>
                            <th>表名称</th>
                            <th>表描述</th>
                            <th>创建时间</th>
                            <th>更新时间</th>
                        </thead>
                        <tbody>
                        {{ range $index, $value := .tables }}
                        <tr>
                            <td>
                                <input type="checkbox" name="'{{$value.TABLE_NAME}}'" value="'{{$value.TABLE_NAME}}'"  lay-skin="primary">
                            </td>
                            <td>{{$value.TABLE_NAME}}</td>
                            <td>{{$value.TABLE_COMMENT}}</td>
                            <td>{{$value.CREATE_TIME}}</td>
                            <td>{{$value.UPDATE_TIME}}</td>
                        </tr>
                        {{else}}
                        <tr>
                            <td colspan="5" style="text-align: center">暂无可导入结果</td>
                        </tr>
                        {{end}}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['laydate','form'], function(){
        var form = layui.form;

        form.on('submit(search)', function(data){
            console.log(data.field)
            let table_name = data.field["table_name"]
            let url = "/v1/gen/notGenList?table_name=" + table_name
            window.location = url
        });
    });
    function multi_import(){
        var ids = [];

        // 获取选中的id
        $('tbody input').each(function(index, el) {
            if($(this).prop('checked')){
                ids.push($(this).val())
            }
        });
        layer.confirm('确认要导入吗？'+ids.toString(),function(){
            //捉到所有被选中的，发异步进行删除
            $.ajax({
                type: "post",
                url: "/v1/gen/batchInitSet",
                data: {
                    table_name_list:ids.toString()
                },
                success: function (res) {
                    if (res.status==1){
                        layer.msg('导入成功', {icon: 1});
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    }else{
                        layer.msg('导入失败', {icon: 2});
                    }
                }
            });
        });
    }

</script>

</html>